package com.springboot.mail.modules.contact.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.springboot.mail.common.bean.DeleteDTO;
import com.springboot.mail.common.bean.MyResult;
import com.springboot.mail.common.bean.PageQueryDTO;
import com.springboot.mail.modules.contact.domain.vo.ContactVO;
import com.springboot.mail.modules.contact.service.ContactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "通讯录模块")
@ApiSupport(author = "LY L")
@RestController
@RequestMapping(value = "/contact", produces = {"application/json;charset=UTF-8"})
@Slf4j
@Validated     // springboot 2.5.* 版本需要在类上标注 @Validated 注解校验注解才会生效。
public class ContactController {

    @Resource
    private ContactService contactService;

    @ApiOperation(value = "通讯录列表分页", notes = "只能查看自己账号的通讯录。")
    @GetMapping("/contactInfo/page")
    public MyResult<Page<ContactVO>> getInfoPageBy(PageQueryDTO pageQueryDTO, ContactVO contactVO) {
        return contactService.getInfoPageBy(pageQueryDTO, contactVO);
    }

    @ApiOperation(value = "查询好友详细信息", notes = "")
    @GetMapping("/contactInfo/{contactId}")
    public MyResult<ContactVO> getInfoByContactId(@PathVariable String contactId) {
        return contactService.getInfoByContactId(contactId);
    }

    @ApiOperation(value = "添加通讯录", notes = "")
    @PostMapping("/add/contactInfo")
    public MyResult<String> addInfo(@RequestBody @Validated ContactVO contactVO) {
        return contactService.addInfo(contactVO);
    }

    @ApiOperation(value = "编辑通讯录", notes = "")
    @PostMapping("/update/contactInfo")
    public MyResult<String> updateInfo(@RequestBody @Validated ContactVO contactVO) {
        return contactService.updateInfo(contactVO);
    }

    @ApiOperation(value = "删除通讯录【单条】", notes = "")
    @DeleteMapping("/delete/contactInfo/{contactId}")
    public MyResult<String> deleteInfo(@PathVariable String contactId) {
        return contactService.deleteInfo(contactId);
    }

    @ApiOperation(value = "删除通讯录【批量】", notes = "")
    @DeleteMapping("/delete/contactInfo/list")
    public MyResult<String> deleteInfoList(@RequestBody @Validated DeleteDTO<String> contactIds) {
        return contactService.deleteInfoList(contactIds);
    }


}